/*
 * PACKAGE NAME: com.jodinfo.outmirror.api.tabledefine.controller
 * FILE    NAME: TableDefineDaoImpl.java
 * COPYRIGHT: Copyright(c) © 2016 heroj Company Ltd. All Rights Reserved
 */
package com.jodinfo.outmirror.api.tabledefine.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSON;
import com.hero.core.entity.ResponseEntity;
import com.jodinfo.outmirror.api.tabledefine.entity.TableDefineEntity;
import com.jodinfo.outmirror.api.tabledefine.service.DymcformBizService;
import com.jodinfo.outmirror.api.tabledefine.service.TableDefineBizService;

@Controller
@RequestMapping(value = "/DymcformDisplayAdmin")
public class DymcformDisplayController {

	@Resource(name = "tableDefineBizService")
	private TableDefineBizService tableDefineBizService;
	@Resource(name = "dymcformBizService")
	private DymcformBizService dymcformBizService;

	/**
	 * list数据源
	 * 
	 * */
	@RequestMapping(value = "/getFormData")
	@ResponseBody
	public String getFormData(String tableName, String pkvalue, String dymcformId, HttpServletRequest request) {
		String str = dymcformBizService.getFormData(tableName, pkvalue, dymcformId, request);
		return str;
	}

	/***
	 * 
	 * 小程序调用查询接口 pkvalue 必填 dymcformId 必填
	 * **/
	@RequestMapping(value = "/getFormDataIntface")
	@ResponseBody
	public String getFormDataIntface(String tableName, String pkvalue, String dymcformId, HttpServletRequest request) {
		String str = dymcformBizService.getFormDataIntface(tableName, pkvalue, dymcformId, request);
		return str;
	}

	/**
	 * getFormPage页面
	 * 
	 * */
	@RequestMapping(value = "/getFormPage")
	public ModelAndView getFormPage(TableDefineEntity tableDefineEntity, String pkvalue, String taskId, String workFlowId, HttpServletRequest request) {
		// tableDefineEntity =
		// tableDefineBizService.queryEntityByTableDefine(tableDefineEntity);
		tableDefineEntity = tableDefineBizService.queryAnalysisEntityByTableDefine(tableDefineEntity, request);
		return new ModelAndView(returnPath("formPage")).addObject("dto", tableDefineEntity).addObject("id", pkvalue).addObject("taskId", taskId).addObject("workFlowId", workFlowId).addObject("taskKey", request.getParameter("taskKey"));
	}

	/**
	 * getSubmitPage页面 保存时一定要存pkvalue回去 ,关掉标签页,防止发生另一个流程, 有参数start 一开始的权限
	 * 
	 * */
	@RequestMapping(value = "/getSubmitPage")
	public ModelAndView getSubmitPage(TableDefineEntity tableDefineEntity, String workFlowId, String workFlowName, HttpServletRequest request) {
		// tableDefineEntity =
		// tableDefineBizService.queryEntityByTableDefine(tableDefineEntity);
		tableDefineEntity = tableDefineBizService.queryAnalysisEntityByTableDefine(tableDefineEntity, request);
		return new ModelAndView(returnPath("submitPage")).addObject("dto", tableDefineEntity).addObject("workFlowId", workFlowId).addObject("workFlowName", workFlowName).addObject("taskKey", request.getParameter("taskKey"));
	}

	/**
	 * 获取子表数据
	 * @author cao.weiwei
	 * @date 2017年4月16日 下午3:25:24
	 * @param tableName
	 *            子表名
	 * @param pkvalue
	 *            子表主键
	 * @param mainTableId
	 *            主表主键
	 * @return
	 */
	@RequestMapping(value = "/getSubTableData")
	@ResponseBody
	public String getSubTableData(String tableName, String pkvalue, String mainTableId) {
		String str = dymcformBizService.getSubTableData(tableName, pkvalue, mainTableId);
		return str;
	}

	/**
	 * list数据源
	 * */
	@RequestMapping(value = "/saveFormData")
	@ResponseBody
	public String saveFormData(@RequestBody TableDefineEntity tableDefineEntity) {
		ResponseEntity rs = dymcformBizService.saveFormData(tableDefineEntity);
		String str = JSON.toJSONString(rs);
		return str;
	}

	/**
	 * 发送数据前的验证
	 * @author cao.weiwei
	 * @date 2017年4月18日 下午4:32:05
	 * @param tableDefineEntity
	 * @return
	 */
	@RequestMapping(value = "/getFlowData")
	@ResponseBody
	public String getFlowData(@RequestBody TableDefineEntity tableDefineEntity) {
		ResponseEntity rs = dymcformBizService.getFlowData(tableDefineEntity);
		String str = JSON.toJSONString(rs);
		return str;
	}

	/**
	 * 小程序获取多个表单的某些字段值 (已不使用)
	 * @author cao.weiwei
	 * @date 2017年5月9日 上午9:45:51
	 * @param tableDefineEntity
	 * @return
	 */
	@RequestMapping(value = "/getDymcformMessageList")
	@ResponseBody
	public String getDymcformMessageList(HttpServletRequest request) {
		String dymcformList = request.getParameter("dymcformList");
		ResponseEntity rs = dymcformBizService.getDymcformMessageList(dymcformList);
		String str = JSON.toJSONString(rs);
		return str;
	}

	/**
	 * 查询采购的设备
	 * @author cao.weiwei
	 * @date 2017年5月15日 下午1:57:02
	 * @param business_no
	 * @return
	 */
	@RequestMapping(value = "/getPurchaseEquipmentList")
	@ResponseBody
	public String getPurchaseEquipmentList(String business_no, String equipmentType) {
		return dymcformBizService.getPurchaseEquipmentList(business_no, equipmentType);
	}

	/**
	 * 获取单据号
	 * @author maoyan
	 * @date 2017年6月15日 下午1:55:45
	 * @param prefix
	 * @return
	 */
	@RequestMapping(value = "/getWoNo")
	@ResponseBody
	public String getWoNo(String prefix) {
		return dymcformBizService.getWoNo(prefix);
	}

	/**
	 * 定义
	 * 
	 */
	private final String MODULE_PATH = "/tabledefine/";

	// 返回路径
	private String returnPath(String jspName) {
		return MODULE_PATH + jspName;
	}
}
